Inside Macintosh: QuickTime

Previous | Chapter Top | Chapter Contents | Next

Movies and Your Event Loop

In order for your movies to play, your application must grant time to the Movie Toolbox. You do this by calling the MoviesTask function from your main event loop. The MoviesTask function causes the Movie Toolbox to service all your active movies. You should call this function regularly so that your movie can play smoothly. You can use the UpdateMovie function to force your movie to be redrawn after it has been uncovered.

You may want your application to take a particular action when a movie is done playing. The Movie Toolbox provides the IsMovieDone function, which allows you to determine whether a movie is done playing. The Movie Toolbox also provides more sophisticated callback mechanisms, which are discussed in "Time Base Functions," .

The Movie Toolbox provides two functions that allow your application to determine whether a specified point lies in either a movie or a track. Use the PtInMovie function with movies; use the PtInTrack function with tracks.

Your application can retrieve some status information about movies and tracks. Use the GetMovieStatus function to retrieve movie status; use the GetTrackStatus function to get track status.

MoviesTask

The MoviesTask function services active movies.

pascal void MoviesTask (Movie theMovie, long maxMilliSecToUse);
theMovie
Specifies the movie for this operation. If you set this parameter to nil , the Movie Toolbox services all of your active movies. Your application obtains this movie identifier from such functions as NewMovie , NewMovieFromFile , and NewMovieFromHandle (described on NewMovie , NewMovieFromFile , and NewMovieFromHandle , respectively).
maxMilliSecToUse
Determines the maximum number of milliseconds that MoviesTask can work before returning. If this parameter is 0, MoviesTask services every active movie exactly once and then returns. If the parameter is nonzero, MoviesTask services as many movies as it can in the allotted time before returning.
Once the MoviesTask function starts servicing a movie, it cannot stop until it has completely met the requirements of the movie. Consequently, the MoviesTask function may execute for a longer time than that specified in maxMilliSecToUse . However, the function does not start servicing a new movie if the time specified by maxMilliSecToUse has elapsed.
The preferred way to use MoviesTask is to set the maxMilliSecToUse parameter to 0; however, if you just want to play one movie, you can call MoviesTask on that one.
If your rate is 0, MoviesTask draws that frame and no other.

DESCRIPTION

When servicing a movie, the Movie Toolbox performs the processing that is appropriate for the movie--displaying frames, playing sound, reading data from disk, or other tasks. The only time the Movie Toolbox actually draws a movie is during the operation of the MoviesTask function.

You should call MoviesTask as often as possible from your application's main event loop. Note that you should call this function after you have performed your own event processing.

The MoviesTask function services only active movies, and only enabled tracks within those active movies. Use the SetMovieActive function (described on SetMovieActive ) and the SetTrackEnabled function (described on SetTrackEnabled ) to enable and disable movies and tracks.

SPECIAL CONSIDERATIONS

Note that the MoviesTask function services only your movies. Your application must call the Event Manager's WaitNextEvent routine (or the Event Manager's GetNextEvent routine and the SystemTask routine) to give other applications the opportunity to call MoviesTask for their movies. For details on WaitNextEvent , GetNextEvent , and SystemTask , see Inside Macintosh: Macintosh Toolbox Essentials .

ERROR CODES

invalidMovie

-2010

This movie is corrupted or invalid

IsMovieDone

Your application may wish to take a particular action when a movie is done playing. The IsMovieDone function allows you to determine if a particular movie has completely finished playing.

pascal Boolean IsMovieDone (Movie theMovie);
theMovie
Specifies the movie for this operation. Your application obtains this movie identifier from such functions as NewMovie , NewMovieFromFile , and NewMovieFromHandle (described on NewMovie , NewMovieFromFile , and NewMovieFromHandle , respectively).

DESCRIPTION

The IsMovieDone function returns true if the specified movie has finished playing; otherwise it returns false . A movie with a positive rate (playing forward) is considered done when its movie time reaches the movie end time. Conversely, a movie with a negative rate (playing backward) is considered done when its movie time reaches the movie start time.

If your application has changed the movie's active segment, the status returned by the IsMovieDone function is relative to the active segment, rather than to the entire movie. You can use the SetMovieActiveSegment function (described on SetMovieActiveSegment ) to change a movie's active segment.

ERROR CODES

invalidMovie

-2010

This movie is corrupted or invalid

UpdateMovie

The UpdateMovie function allows your application to ensure that the Movie Toolbox properly displays your movie after it has been uncovered.

Your application should call this function between the Window Manager's BeginUpdate and EndUpdate functions. (For details, see Inside Macintosh: Macintosh Toolbox Essentials .) Do not call MoviesTask at this time. You will observe better display behavior if you call MoviesTask at the end of your update processing.

pascal OSErr UpdateMovie (Movie theMovie);
theMovie
Specifies the movie for this operation. Your application obtains this movie identifier from such functions as NewMovie , NewMovieFromFile , and NewMovieFromHandle (described on NewMovie , NewMovieFromFile , and NewMovieFromHandle , respectively).

DESCRIPTION

The UpdateMovie function does not actually update the movie's graphics world. Rather, the function invalidates the movie's display state so that the Movie Toolbox redraws the movie the next time you call the MoviesTask function. If you need to force a movie to be redrawn outside of a Window Manager update sequence, your application can call UpdateMovie and then call the MoviesTask function (described on MoviesTask ) to service the movie.

The Movie Toolbox determines the portion of the screen to update by examining the graphics port's visible region.

ERROR CODES

invalidMovie

-2010

This movie is corrupted or invalid

SEE ALSO

For sample code that uses the UpdateMovie function in a Window Manager update sequence, see Listing 13 .

PtInMovie

The PtInMovie function allows your application to determine whether a specified point lies in the region defined by a movie's final display boundary region after it has been clipped by the movie's display clipping region. This function is accurate at the current movie time.

pascal Boolean PtInMovie (Movie theMovie, Point pt);
theMovie
Specifies the movie for this operation. Your application obtains this movie identifier from such functions as NewMovie , NewMovieFromFile , and NewMovieFromHandle (described on NewMovie , NewMovieFromFile , and NewMovieFromHandle , respectively).
pt
Specifies the point to be checked. This point must be expressed in the movie's local display coordinate system.

DESCRIPTION

The PtInMovie function returns a Boolean value. The function sets this value to true if the point lies in the movie's display space.

SPECIAL CONSIDERATIONS

The region that PtInMovie checks for is different from the movie box.

ERROR CODES

invalidMovie

-2010

This movie is corrupted or invalid

SEE ALSO

To find out if a point lies in the region defined by a track's display boundary region after it has been clipped by a movie's final display clipping region, you use the PtInTrack function. See the next section for details.

PtInTrack

The PtInTrack function allows your application to determine whether a specified point lies in the region defined by a track's display boundary region after it has been clipped by the movie's final display clipping region. This function is accurate at the current movie time.

pascal Boolean PtInTrack (Track theTrack, Point pt);
theTrack
Specifies the track for this operation. Your application obtains this track identifier from such Movie Toolbox functions as NewMovieTrack and GetMovieTrack (described on NewMovieTrack and GetMovieTrack , respectively).
pt
Specifies the point to be checked. This point must be expressed in the local display coordinate system of the movie that contains the track.

DESCRIPTION

The PtInTrack function returns a Boolean value. The function sets this value to true if the point lies in the track's display space.

SPECIAL CONSIDERATIONS

The region that PtInTrack checks for is different from the movie box.

ERROR CODES

invalidMovie

-2010

This movie is corrupted or invalid

SEE ALSO

To find out if a point lies within the region defined by a movie's final display boundary region after it has been clipped by the movie's display clipping region, you can use the PtInMovie function, which is described in the previous section.

GetMovieStatus

The GetMovieStatus function searches for errors in all the enabled tracks of the movie. This function returns information about errors that are encountered during the processing associated with the MoviesTask function (described on MoviesTask ). These errors typically reflect playback problems, such as low-memory conditions.

pascal ComponentResult GetMovieStatus (Movie theMovie,
                                         Track *firstProblemTrack);
theMovie
Specifies the movie for this operation. Your application obtains this movie identifier from such functions as NewMovie , NewMovieFromFile , and NewMovieFromHandle (described on NewMovie , NewMovieFromFile , and NewMovieFromHandle , respectively).
firstProblemTrack
Contains a pointer to a track identifier. The Movie Toolbox places the identifier for the first track that is found to contain an error into the field referred to by this parameter. If you do not want to receive the track identifier, set this parameter to nil .

DESCRIPTION

The GetMovieStatus function returns the error from the first problem track. If the component does not find any errors, the result is set to noErr .

ERROR CODES

Any Movie Toolbox result code (see "Summary of the Movie Toolbox" at the end of this chapter)

GetTrackStatus

The GetTrackStatus function returns the value of the last error the media encountered while playing a specified track. This function returns information about errors that are encountered during the processing associated with the MoviesTask function (described on MoviesTask ). These errors typically reflect playback problems, such as low-memory conditions.

The media clears this error code when it detects that the error has been corrected.

pascal ComponentResult GetTrackStatus (Track theTrack);
theTrack
Specifies the track for this operation. Your application obtains this track identifier from the GetMovieStatus function, described in the previous section.

DESCRIPTION

The GetTrackStatus function returns the last error encountered for the specified track. If the component does not find any errors, the result is set to noErr .

ERROR CODES

Any Movie Toolbox result code (see "Summary of the Movie Toolbox" at the end of this chapter)


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next